From aba1db82f5f4ebe9d63dbb940abc8e25e5c29489 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 23 Jul 2015 08:59:02 +0100 Subject: [PATCH] libxl: use thread-safe localtime_r and handle NULL Signed-off-by: Wei Liu Acked-by: Ian Campbell --- tools/libxl/libxl_x86.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index b3cf3e238a..b379e09b20 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -306,10 +306,16 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, rtc_timeoffset = d_config->b_info.rtc_timeoffset; if (libxl_defbool_val(d_config->b_info.localtime)) { time_t t; - struct tm *tm; + struct tm *tm, result; t = time(NULL); - tm = localtime(&t); + tm = localtime_r(&t, &result); + + if (!tm) { + LOGE(ERROR, "Failed to call localtime_r"); + ret = ERROR_FAIL; + goto out; + } rtc_timeoffset += tm->tm_gmtoff; } @@ -335,6 +341,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, } } +out: return ret; } -- 2.30.2